<template>
  <div class="DRC_box">
    <!--头部标签栏-->
    <div class="tabs">
      <span
        v-for="item in ['早餐', '中餐', '晚餐']"
        :key="item"
        :class="active == item.substring(0, 1) ? 'active' : ''"
        @click="handleTab(item.substring(0, 1))"
        >{{ item }}</span
      >
    </div>
    <!--内容列表-->
    <div class="list">
      <ContentListItem
        v-for="item in newOrderHistoryList"
        :orderHistoryList="item"
        :key="item.menu_id"
      />
    </div>
  </div>
</template>

<script>
import { ref } from "vue";
import ContentListItem from "./ContentListItem";
import { getOrderHistory } from "../../../api/ordering";

export default {
  name: "DRecordsContent",
  components: { ContentListItem },
  setup() {
    const active = ref("早");
    //数据
    const orderHistoryList = ref([]);
    const newOrderHistoryList = ref(); //代理数据集
    getOrderHistory().then((res) => {
      // console.log(res);
      orderHistoryList.value = res.data;
      newOrderHistoryList.value = orderHistoryList.value.filter(
        (item) => item.menu_type == "早"
      );
    });
    //切换类型
    const handleTab = (value) => {
      active.value = value;
      newOrderHistoryList.value = orderHistoryList.value.filter(
        (item) => item.menu_type == value
      );
      // console.log(active.value);
    };
    return { active, handleTab, newOrderHistoryList };
  },
};
</script>

<style scoped lang="less">
.tabs {
  position: fixed;
  top: 2.5rem;
  width: 100%;
  height: 2rem;
  box-sizing: border-box;
  display: flex;
  justify-content: space-around;
  background-color: #fff;
  align-items: center;
  z-index: 1;
  span {
    color: #646566;
    font-size: 1.05rem;
    padding: 0.2rem 0.4rem;
  }
  .active {
    border-bottom: 2px solid #ff8917;
  }
}
.list {
  padding: 0 0.3rem;
  box-sizing: border-box;
}
</style>
